package lambda;

import java.util.function.Predicate;

/**
 * 判断函数
 */
public class PredicateTest {
    public static void main(String[] args) {
        greaterThanOne(num -> num > 1);
        LessThanOne(num -> num > 1);
        betweenOneAndTen(num -> num > 1, num -> num < 10);
        greaterThanFiveOrLessTanTwo(num -> num > 5, num -> num < 2);
    }

    /**
     * 单次判断
     */
    private static void greaterThanOne(Predicate<Integer> predicate) {
        boolean test = predicate.test(10);
        System.out.println("test = " + test);
    }

    /**
     * 单次判断（取反）
     */
    private static void LessThanOne(Predicate<Integer> predicate) {
        boolean test = predicate.negate().test(10);
        System.out.println("test = " + test);
    }

    /**
     * 多次判断（且关系）
     */
    private static void betweenOneAndTen(Predicate<Integer> p1, Predicate<Integer> p2) {
        boolean test = p1.and(p2).test(2);
        System.out.println("test = " + test);
    }

    /**
     * 多次判断（或关系）
     */
    private static void greaterThanFiveOrLessTanTwo(Predicate<Integer> p1, Predicate<Integer> p2) {
        boolean test = p1.or(p2).test(3);
        System.out.println("test = " + test);
    }
}
